<?php


namespace app\admin\controller\manage;


use app\common\Common;
use app\sys\model\Team as TeamModel;
use think\facade\Validate;
use think\Request;

class Team extends Common
{
    // 列表
    public function methodList(Request $request)
    {
        $search = $request->param("search","");
        $page = $request->param("page",0);
        $limit = $request->param("limit",10);
        $data = TeamModel::ModelList($search,$page,$limit);
        return successJson("success",$data);
    }

    // 添加
    public function methodAdd(Request $request)
    {
        $data = $request->param();
        $data["next_month"] = $request->param("next_month",[]);
        $data["name"] = $request->param("name","");
        $data["month"] = $request->param("month",[]);
        $data["week"] = $request->param("week",[]);
        $data["other_day"] = $request->param("other_day",[]);

        $res = TeamModel::ModelAdd($data);
        if($res){
            return failedJson($res);
        }
        return successJson("success");
    }

    // 修改
    public function methodUp(Request $request)
    {
        $data = $request->param();
        $data["next_month"] = $request->param("next_month",[]);
        $data["name"] = $request->param("name","");
        $data["month"] = $request->param("month",[]);
        $data["week"] = $request->param("week",[]);
        $data["other_day"] = $request->param("other_day",[]);
        $id = $request->param("id",0);

        $res =  TeamModel::ModelUp($id,$data);
        if($res){
            return failedJson($res);
        }
        return successJson("success");
    }

    // 删除
    public function methodDel(Request $request)
    {
        $ids= $request->param("id",[]);
        $res = TeamModel::ModelDel($ids);
        if($res){
            return failedJson($res);
        }
        return successJson("success");
    }

    // 详情
    public function methodDet(Request $request)
    {
        $id = $request->param("id",0);
        $data = TeamModel::ModelDet($id);
        return successJson("success",$data);
    }

    // 详情
    public function methodSetList(Request $request)
    {
        $res = TeamModel::TeamSetList()->toArray();
        $data = array_merge([["id" => 0,"name" => "未分组"]],$res);
        return successJson("success",$data);
    }

    // 详情
    public function methodSet(Request $request)
    {
        $staffId = $request->param("staff_id",[]);
        $teamId = $request->param("team_id",0);
        $data = TeamModel::TeamSet($staffId,$teamId);
        return successJson("success",$data);
    }
}